package com.senac.parser;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import com.senac.model.Aluno;

public class AlunoParser extends Parser<Aluno>{

	
	public AlunoParser(ResultSet rs) {
		super(rs);		
	}

	@Override
	public Aluno parse() throws SQLException {
		
		Aluno aluno = new Aluno();
		
		ResultSetMetaData md = getRs().getMetaData();
		
		for (int i = 1; i <= md.getColumnCount(); i++) {
			String columnName = md.getColumnName(i).toLowerCase();
			
			switch (columnName) {
			case "id":
				aluno.setId(getRs().getInt(columnName));
				break;
			case "nome":
				aluno.setNome(getRs().getString(columnName));
				break;
			case "rg":
				aluno.setRg(getRs().getString(columnName));
				break;
			case "carga_horaria":
				aluno.setCargaHoraria(getRs().getInt(columnName));
				break;
				
			default:
				break;
			}
		}
		
		return aluno;
		
	}
	
	
}
